package 力扣日常刷题.木22二月.第01天206;

import 力扣日常刷题.TreeNode;

import java.util.ArrayDeque;

/**
 * @author 帅小伙
 * @date 2022/2/6
 * @description
 */
public class Demo10JZ二叉树镜像2 {


    public TreeNode mirrorTree(TreeNode root) {

        if(root==null){
            return null;
        }
        ArrayDeque<TreeNode> queue=new ArrayDeque<TreeNode>();
        queue.add(root);

        while(!queue.isEmpty()){
            int size=queue.size();
            for(int i=0;i<size;i++){
                TreeNode pop=queue.pop();

                TreeNode temp=pop.right;
                pop.right=pop.left;
                pop.left=temp;
                if(pop.right!=null){
                    queue.add(pop.right);
                }
                if(pop.left!=null){
                    queue.add(pop.left);
                }
            }
        }
        return root;
    }

}
